<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
  <title>Sidebar Toggle</title>
  <style>
    .container {
  display: flex;
}

.sidebar {
  width: 200px;
  background-color: #f0f0f0;
  transition: width 0.3s ease;
  position: sticky;
}

.sidebar-content {
  padding: 10px;
}

.main-content {
  flex: 1;
  background-color: #fff;
  padding: 10px;
}

button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
}
  </style>
</head>

<body>
  <div class="container">
    <div class="sidebar" id="sidebar">
      <div style="background-color: blue; color: white" id="toggleButton"> &gt; &gt;</div>
      <div class="sidebar-content">
        <p>这里是侧边栏内容</p>
      </div>
    </div>
    <div class="main-content">
      <p>这里是主要内容区域</p>
    </div>
  </div>
  <script >


document.addEventListener('DOMContentLoaded', function () {
  const toggleButton = document.getElementById('toggleButton');
  const sidebar = document.getElementById('sidebar');
  let isExpanded = false;

  toggleButton.addEventListener('click', function () {
    if (isExpanded) {
      sidebar.style.width = '200px';
      toggleButton.textContent = '→';
    } else {
      sidebar.style.width = '0';
      toggleButton.textContent = '←';
    }
    isExpanded =!isExpanded;
  });
});
  </script>
</body>

</html>